package com.honeybee.cloud.framework.gateway.fallback;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import java.io.Serializable;

/**
 * @Description 请求返回结果集
 * @Author cheng
 * @Create 2018-12-08
 * @Since 1.0.0
 */
@Data
@SuppressWarnings("unchecked")
public class FallBackResult<T> implements Serializable {

    /**
     * 获取调用返回值
     */

    private T data;
    /**
     * 状态码 0成功 其他
     */
    private Integer parentCode;
    /**
     * 子状态码 0成功 其他
     */
    private Integer subCode;


    private Boolean success;

    /**
     * 异常信息
     */
    private String message;


    public FallBackResult(Integer parentCode, Integer subCode, String message) {
        this.parentCode = parentCode;
        this.subCode = subCode;
        this.message = message;
    }



    public static FallBackResult error(Integer parentCode, Integer subCode, String message) {
        FallBackResult result = new FallBackResult(parentCode, subCode, message);
        result.setSuccess(false);
        return result;
    }

    public static FallBackResult error(Integer parentCode, String message) {
        return error(parentCode, null, message);
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

}
